﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace MyVideo
{
    public partial class PlayVideo : UserControl
    {
        public PlayVideo()
        {
            InitializeComponent();
        }

        private void buttonX1_Click(object sender, EventArgs e)
        {
            OpenFileDialog openFileDialog = new OpenFileDialog();
            //openFileDialog.Filter = "MP3文件|*.mp3|所有文件|*.*";
            openFileDialog.RestoreDirectory = false;
            openFileDialog.FilterIndex = 1;
            if (openFileDialog.ShowDialog() == DialogResult.OK)
            {
                string fileName = openFileDialog.FileName;
                //WMPLib.IWMPPlaylist playList = axWindowsMediaPlayer2.playlistCollection.newPlaylist("mylist");
                //playList.appendItem((WMPLib.IWMPMedia)this.axWindowsMediaPlayer2.newMedia(fileName));
                //axWindowsMediaPlayer2.currentPlaylist = playList;
                axWindowsMediaPlayer2.URL = fileName;
                axWindowsMediaPlayer2.Ctlcontrols.play();
            }
        }

        protected override void OnResize(EventArgs e)
        {
            panelEx1.Location = new Point((this.Width - panelEx1.Width) / 2, (this.Height - panelEx1.Height - 80) / 2);
            base.OnResize(e);
        }

        private void PlayVideo_DragDrop(object sender, DragEventArgs e)
        {
            string[] files = (string[])e.Data.GetData(DataFormats.FileDrop, false);
            axWindowsMediaPlayer2.URL = files[0];
            axWindowsMediaPlayer2.Ctlcontrols.play();
        }

        private void PlayVideo_DragEnter(object sender, DragEventArgs e)
        {
            if (e.Data.GetDataPresent(DataFormats.FileDrop))
            {
                e.Effect = DragDropEffects.All;
            }
            else
            {
                e.Effect = DragDropEffects.None;
            }
        }
    }
}
